package cn.dankal.flyaudio.pop;

import android.content.Context;
import android.view.View;

import cn.dankal.flyaudio.R;
import cn.dankal.flyaudio.configs.PayConfigs;
import razerdp.basepopup.BasePopupWindow;

public class PayMethodPop extends BasePopupWindow implements View.OnClickListener {

    private View weChatPayView;
    private View alipayView;

    public PayMethodPop(Context context) {
        super(context);
    }

    @Override
    public View onCreateContentView() {
        return createPopupById(R.layout.pop_pay_method);
    }

    public int getPayMethod() {
        if (weChatPayView.isSelected()) {
            return PayConfigs.PAY_METHOD_WECHAT;
        }
        if (alipayView.isSelected()) {
            return PayConfigs.PAY_METHOD_ALIPAY;
        }
        return 0;
    }

    @Override
    public void onViewCreated(View contentView) {
        super.onViewCreated(contentView);
        weChatPayView = findViewById(R.id.rl_wechat_pay);
        alipayView = findViewById(R.id.rl_alipay);
        weChatPayView.setOnClickListener(this);
        alipayView.setOnClickListener(this);
        findViewById(R.id.iv_close).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        switch (id) {
            case R.id.rl_wechat_pay:
                weChatPayView.setSelected(true);
                alipayView.setSelected(false);
                dismiss();
                break;
            case R.id.rl_alipay:
                weChatPayView.setSelected(false);
                alipayView.setSelected(true);
                dismiss();
                break;
            case R.id.iv_close:
                dismiss();
                break;
        }
    }
}
